package org.nowcoder.huawei.other;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * HJ101: 输入整型数组和排序标识，对其元素按照升序或降序进行排序
 */
public class HJ101 {
    public static void hj101(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] vals = new int[n];
        int index = 0;
        for (String tmp : br.readLine().split(" ")) {
            vals[index++] = Integer.parseInt(tmp);
        }
        int flag = Integer.parseInt(br.readLine());
        Arrays.sort(vals);
        if (flag == 1) {
            for (int i = n - 1; i >= 0; i--) {
                System.out.print(vals[i] + " ");
            }
        } else {
            for (int i = 0; i < n; i++) {
                System.out.print(vals[i] + " ");
            }
        }
    }
}
